#include "framebufferobject.h"

#include "texture2d.h"

namespace GL
{

FramebufferObject::FramebufferObject()
: m_Id(0)
{
    glGenFramebuffersEXT(1, &m_Id);
}
    
FramebufferObject::~FramebufferObject()
{
    glDeleteFramebuffersEXT(1, &m_Id);
}

void FramebufferObject::attachTexture(GLuint texId, GLenum target, GLuint attachIndex)
{
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_Id);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachIndex, target, texId, 0);
}

void FramebufferObject::bind()
{
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_Id);
}

void FramebufferObject::unbind()
{
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}

bool FramebufferObject::statusOK()
{
    GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    return (status == GL_FRAMEBUFFER_COMPLETE_EXT);
}

}
